package api

import (
	"gitee.com/gopher2011/gva/server/dao"
	"github.com/gin-gonic/gin"
)

// casbinRuleApi 管理对象。
var CasbinRule = &casbinRuleApi{}
// casbin_规则表
type casbinRuleApi struct{}


// @Summary 更新角色api权限
// @Param data body dao.CasbinInReceive true "权限id, 权限模型列表"
// @Router /casbin/UpdateCasbin [post]
func (it *casbinRuleApi) UpdateCasbin(c *gin.Context) {
	var ptr dao.CasbinInReceive
	err := c.ShouldBind(&ptr)
	if err != nil {
		FailWithMessage(c,err.Error())
		return
	}
	if err = dao.CasbinRuleDao.UpdateCasbin(ptr.AuthorityId, ptr.CasbinInfos);err != nil {
		FailWithMessage(c,"更新失败")
	}else {
		OkWithMessage(c,"更新成功")
	}
}

// @Summary 获取权限列表
// @Param data body dao.CasbinInReceive true "权限id, 权限模型列表"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func (it *casbinRuleApi) GetPolicyPathByAuthorityId(c *gin.Context) {
	var ptr dao.CasbinInReceive
	err := c.ShouldBind(&ptr)
	if err != nil {
		FailWithMessage(c,err.Error())
		return
	}
	paths := dao.CasbinRuleDao.GetPolicyPathByAuthorityId(ptr.AuthorityId)
	OkWithDetailed(c,"获取成功",PolicyPathResponse{Paths: paths})
}
